<template>
  <div> 
      <h2>修改增加</h2>
      <table>
        <tbody>
          <tr>
            <td>会员等级名称</td>
            <td><input type="text" v-model="state.LevelName"></td>
          </tr>
          <tr>
            <td></td>
            <td><input type="button" value="修改" @click="add"></td>
          </tr>
        </tbody>
      </table>
  </div>
</template>

<script setup lang="ts">

import { reactive,toRefs,onMounted } from 'vue';
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router'; 
const router = useRouter();
const route=useRoute();

onMounted(()=>{
  ftlist();
})

const ftlist=()=>{
  let obj={
    LevelId:route.query.LevelId,
  }
  axios({
    url:'/api/one/Levelft/Levelft',
    method:'get',
    params:obj
  }).then((res)=>{
    console.log(res)
    state.value=res.data.data
  })
  .catch((err)=>{
    console.log(err)
  })
}


let data:any =reactive({
  state:{
    LevelName:''
  }
})
let {state}=toRefs(data);

const add=()=>{
  if(state.value.LevelName==''){
      alert('等级名称不能为空');
      return;
  }

  let obj={
    LevelId:route.query.LevelId,
    LevelName:state.value.LevelName,
  }

  axios({
    url:'/api/one/LevelUpdate/LevelUpdate',
    method:'put',
    data:obj
  }).then((res)=>{
    console.log(res)
    if(res.data.data==-1){
      alert('名称重名');
      return;
    }
    else if(res.data.data==1){
      alert('成功');
      router.push('/main/memberLevelList')
      return;
    }
    else
    {
      alert('失败');
      return;
    }
  }).catch((err)=>{
    console.log(err)
  })


}

</script>

<style scoped>

</style>